<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>健康评估<small>体检风险评估</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>健康评估</el-breadcrumb-item>
            <el-breadcrumb-item>体检风险评估</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号/姓名" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>

            <!--页面主体-->
            <el-table size="medium" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <!--                <el-table-column type="index" align="center" label="序号"></el-table-column>-->
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="assTime" label="评估时间" align="center"></el-table-column>
                <el-table-column label="操作" align="center" width="250px">
                    <template slot-scope="scope">
                        <el-button type="primary" size="medium" @click="findRiskReport(scope.row)">查看风险报告</el-button>
                        <el-button size="medium" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <!--分页-->
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增" :visible.sync="dialogFormVisible" width="60%">
                    <el-form label-position="right" label-width="100px" :rules="rules" :model = "formData">
                        <el-row>
                            <el-col :span="10">
                                <el-form-item label="档案号：">
                                    <el-input v-model="formData.fileNumber"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-button type="primary" @click="findByFileId()">查询体检报告</el-button>
                            </el-col>
                        </el-row>

                        <el-table :data="report">
                            <el-table-column property="name" label="体检人" width="150"></el-table-column>
                            <el-table-column property="checkItem" label="项目名称" width="150"></el-table-column>
                            <el-table-column property="result" label="结果" ></el-table-column>
                            <el-table-column property="leftCritical" label="左临界值"></el-table-column>
                            <el-table-column property="rightCritical" label="右临界值"></el-table-column>
                            <el-table-column property="company" label="单位"></el-table-column>
                        </el-table>

                    </el-form>

                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">关闭</el-button>
                        <el-button type="primary" @click="handleAddRiskAssessment()">进行健康风险评估</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="查看报告" :visible.sync="dialogFormVisible4Edit" width="40%">
                    <template>
                        <el-table :data="tableData" >
                            <el-table-column property="name" label="评估人" width="100"></el-table-column>
                            <el-table-column property="checkItem" label="项目名称" width="100"></el-table-column>
                            <el-table-column property="result" label="结果" width="100" ></el-table-column>
                            <el-table-column property="assessment" label="评估" >
                                <template slot-scope="scope">
                                    <el-tag type="danger" v-if="scope.row.assessment=='高'">{{scope.row.assessment}}</el-tag>
                                    <el-tag type="success" v-if="scope.row.assessment=='正常'">{{scope.row.assessment}}</el-tag>
                                    <el-tag type="warning" v-if="scope.row.assessment=='低'">{{scope.row.assessment}}</el-tag>
                                </template>
                            </el-table-column>
                        </el-table>

                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">关闭</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 1,//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            dataList: [],//列表数据

            report: [], //查询出的报告结果
            formData: {
                fileNumber:"",//档案号
            },//表单数据
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            checkitemIds: [],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                radio: [{required: true, message: '不能空选啊兄dei', trigger: 'change'}],
                fileId: [{required: true, message: '档案号不为空', trigger: 'blur'}],
                name: [{required: true, message: '名字不为空', trigger: 'blur'}],
                sex: [{required: true, message: '性别不为空', trigger: 'blur'}],
                age: [{required: true, message: '年龄不为空', trigger: 'blur'}],
            }
        },
        created() {
            this.findPage();
        },
        methods: {
            findByFileId() {
                axios.get("/riskAssessment/findReportByFileNumber.do?fileNumber=" + this.formData.fileNumber)
                    .then(res => {
                        res = res.data;
                        if (res.flag) {
                            this.formData.report = res.data;
                            this.report = res.data;
                            console.log(this.formData);
                        } else {
                            this.$message.error(res.message);
                        }
                        // console.log(res.data);
                    });
            },

            //添加
            handleAddRiskAssessment() {
                axios.post("/riskAssessment/addRiskAssessment.do", this.formData).then((res) => {
                    //判断后台返回的flag值，true表示添加操作成功，false为添加操作失败
                    if (res.data.flag) {
                        this.$message.success(res.data.message);
                    } else {
                        this.$message.error(res.data.message);
                    }
                }).finally(() => {
                    //隐藏新增窗口
                    this.dialogFormVisible = false;
                    //调用分页查询方法
                    this.findPage();
                })
            },
            //分页查询
            findPage() {
                //分页查询的参数
                let temple = this.pagination.queryString;
                let param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: (temple != null && temple === "") ? null : temple
                };
                if (param.queryString != null) {
                    param.currentPage = 1;
                }
                //异步进行分页查询
                axios.post("/riskAssessment/findPage.do", param).then((res) => {
                    //将分页查询的结果绑定到页面中
                    this.dataList = res.data.rows;
                    console.log(this.dataList);
                    this.pagination.total = res.data.total;
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
                this.report = [];
                this.activeName = 1;
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.findAll();
                this.dialogFormVisible = true;
            },

            // 弹出查看报告窗口
            findRiskReport(row) {
                this.resetForm();
                axios.get("/riskAssessment/findRiskReportByFileNumber/" + row.fileNumber + ".do").then((res) => {
                    console.log(res.data.data);
                    if (res.data.flag) {
                        this.tableData = res.data.data;
                        console.log(this.tableData)
                    } else {
                        this.$message.error(res.message);
                    }
                });
                this.dialogFormVisible4Edit = true;
            },

            findAll() {
                //查询全部体质并赋值到tab pane列表
                axios.get("/physique/findAll.do").then((res) => {
                    if (res.data.flag) {
                        this.physiqueData = res.data.data;
                        console.log(this.formData);
                    } else {
                        this.$message.error(res.data.message);
                    }
                });
            },

            //切换页码
            handleCurrentChange(currentPage) {
                //使用临时变量存储搜索框中数据
                var queryString = this.pagination.queryString;
                //修改搜索框中的数据为null
                this.pagination.queryString = null;
                //修改分页查询页码为选中页码
                this.pagination.currentPage = currentPage;
                //调用分页查询
                this.findPage();
                //将搜索框中数据重写回搜索框
                this.pagination.queryString = queryString;
            },


            // 删除
            handleDelete(row) {
                this.$confirm('此操作将删除条数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/riskAssessment/delete/" + row.fileNumber + ".do").then((res) => {
                        if (res.data.flag) {
                            this.$message.success(res.data.message);
                        } else {
                            this.$message.error(res.data.message);
                            return false;
                        }
                    }).finally(() => {
                            this.findPage();
                        }
                    );
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                });
            }
        }
    })
</script>
</html>
